package com.cms.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cms.common.StringUtils;
import com.cms.constant.CmsConstant;
import com.cms.model.TrAdminUser;
import com.cms.model.TrPageCatalog;
import com.cms.service.PageCatalogService;
import com.cms.service.ReportService;

@Controller
public class PageCatalogController extends BaseController
{
	 @Autowired
     private PageCatalogService pageCatalogService;	
	 
	 @Autowired
	 private ReportService reportService;
	 
	 /***
	  * 
	  * @param req
	  * @param resp
	  * @param map
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping("/pageCatalog.do")
	 public String enterPageContent(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 {  
		 Map<String,Object>param = new HashMap<String, Object>();
		 param.put(CmsConstant.CATALOG_NAME, "CATALOG_STATUS");
		 map.put("CATALOG_STATUS", this.reportService.getReportResult(CmsConstant.CATALOG_CODE, param));
		 return "pageCatalog/pageCatalogMain.html";
	 }
	 
	 /***
	  * 
	  * @param req
	  * @param resp
	  * @param map
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping("/toEditCatalog.do")
	 public String toEditPageCatalog(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 { 
		 String catalogId = req.getParameter("catalogId");
		 TrPageCatalog catalog= new TrPageCatalog();
		 catalog.setId(StringUtils.str2Int(catalogId));
		 Map<String,Object>param = new HashMap<String, Object>();
		 param.put(CmsConstant.CATALOG_NAME, "CATALOG_STATUS");
		 map.put("CATALOG_STATUS", this.reportService.getReportResult(CmsConstant.CATALOG_CODE, param));
		 map.put("catalog", this.pageCatalogService.getPageCatalogById(catalog));
		 map.put("action", "pageCatalog/updatePageCatalog.do");
		 return "pageCatalog/pageCatalogInfo.html";
	 }
	 
	 /**
	  * 
	  * @param req
	  * @param resp
	  * @param map
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping("/toAddCatalog.do")
	 public String toAddPageCatalog(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 { 
		 Map<String,Object>param = new HashMap<String, Object>();
		 param.put(CmsConstant.CATALOG_NAME, "CATALOG_STATUS");
		 map.put("CATALOG_STATUS", this.reportService.getReportResult(CmsConstant.CATALOG_CODE, param));
		 map.put("catalog", new TrPageCatalog());
		 map.put("action", "pageCatalog/savePageCatalog.do");
		 return "pageCatalog/pageCatalogInfo.html";
	 }
	 
	 /***
	  * 
	  * @param req
	  * @param resp
	  * @param map
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping("/pageCatalog/savePageCatalog.do")
	 public void savePageCatalog(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 { 
		  TrPageCatalog catalog = new TrPageCatalog();
		  TrAdminUser tu= this.getLoginUser(req);
		  catalog.setCreateUser(tu.getId());
		  catalog.setModifyUser(tu.getId());
		  this.export(req, "catalog", catalog);
		  this.pageCatalogService.savePageCatalog(catalog);
	 }
	 
	 /**
	  * 
	  * @param req
	  * @param resp
	  * @param map
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping("/pageCatalog/updatePageCatalog.do")
	 public void updatePageCatalog(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 { 
		  TrPageCatalog catalog = new TrPageCatalog();
		  TrAdminUser tu= this.getLoginUser(req);
		  catalog.setCreateUser(tu.getId());
		  catalog.setModifyUser(tu.getId());
		  this.export(req, "catalog", catalog);
		  this.pageCatalogService.updatePageCatalog(catalog);
	 }
	 
	 @RequestMapping("/pageCatalogList.do") 
	 public String pageContentList(HttpServletRequest req,HttpServletResponse resp,ModelMap map)throws Exception
	 {
		 Map<String,Object>param = this.buildQueryMap(req);
		 map.put("pageCatalogList", this.reportService.pagingReportResult("pagingPageCatalog", param));
		 return "pageCatalog/pageCatalogList.html";
	 }
	 
}
